package com.kvest.ula.android;

import java.util.ArrayList;

import com.kvest.ula.R;
import com.kvest.ula.core.Settings;
import com.kvest.ula.datamodel.Element;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CityListAdapter extends ArrayAdapter<Element>
{
	private ArrayList<Element> items;
	private LayoutInflater inflater;
	private int viewResourceId;
	
	public CityListAdapter(Context context, int viewResourceId, ArrayList<Element> items)
	{
		super(context, viewResourceId, items);
        this.inflater = LayoutInflater.from(context);
        this.items = items;
        this.viewResourceId = viewResourceId;
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
    	View view = convertView;
    	if (view == null) 
        {
    		view = this.inflater.inflate(viewResourceId, null);
        }
    	
    	Element element = items.get(position);
    	TextView name = (TextView) view.findViewById(R.id.list_item_text);
    	
		if (element != null && name != null) 
        {
			name.setTextSize(Settings.getSettings().getFullFontSize());
			
        	name.setText(Html.fromHtml(element.getName()));
        }
    	return view;
    }
}
